<template>
  <div>
     <van-button
            class="follow-btn"
            type="info"
            color="#3296fa"
            round
            size="small"
            icon="plus"
            v-if="!isFollow"
            @click="onFollowed"
          >关注</van-button>
          <van-button
            class="follow-btn"
            round
            size="small"
            v-else
            @click="onFollowed"
          >已关注</van-button>
  </div>
</template>

<script>
import { addFollowUser, removeFollowUser } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    isFollow: {
      type: Boolean,
      require: true
    },
    autId: {
      type: [Number, Object],
      require: true
    }
  },
  model: {
    prop: 'isFollow',
    event: 'updateFollow'
  },
  data () {
    return {

    }
  },

  created () {

  },

  methods: {
    async onFollowed () {
      try {
        if (this.isFollow) {
          await removeFollowUser(this.autId)
          Toast.success('取消关注')
        } else {
          await addFollowUser(this.autId)
          Toast.success('关注成功')
        }
        // this.article.is_followed = !this.article.is_followed
        this.$emit('updateFollow', !this.isFollow)
      } catch (error) {
        Toast.fail('操作失败')
      }
    }
  }
}
</script>

<style scoped>

</style>
